//
//  GMMyselfVC.m
//  StockSystem
//
//  Created by 小熊 on 2018/5/23.
//  Copyright © 2018年 小熊. All rights reserved.
//

#import "GMMyselfVC.h"
#import "GMMyselfViewCell.h"
#import "GMMyselfSecondCell.h"
#import "GMRowItem.h"
#import "GMGroupItem.h"
#import "GMMyselfHeaderView.h"

#import "GMTrainViewController.h"
#import "GMStudyViewController.h"
#import "GMPracticeViewController.h"
#import "GMExamViewController.h"
#import "GMQuestionViewController.h"
#import "GMNotesViewController.h"
#import "GMTodayTaskVC.h"
@interface GMMyselfVC ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tabView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) GMMyselfHeaderView *headerView;
@end

@implementation GMMyselfVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tabView registerNib:[UINib nibWithNibName:@"GMMyselfViewCell" bundle:nil] forCellReuseIdentifier:@"GMMyselfViewCell"];
    [self.tabView registerNib:[UINib nibWithNibName:@"GMMyselfSecondCell" bundle:nil] forCellReuseIdentifier:@"GMMyselfSecondCell"];
    [self setGroupOne];
    [self setGroupTwo];
    self.tabView.tableHeaderView = self.headerView;
}
- (NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource =[[NSMutableArray alloc]init];
    }
    return _dataSource;
}
- (void) setGroupOne{
    GMRowItem *firstItem = [GMRowItem itemWithTitle:@"培训记录" image:[UIImage imageNamed:@"bbb"]];
    GMRowItem *secondItem = [GMRowItem itemWithTitle:@"学习记录" image:[UIImage imageNamed:@"bbb"]];
    GMRowItem *threeItem = [GMRowItem itemWithTitle:@"练习记录" image:[UIImage imageNamed:@"bbb"]];
    GMRowItem *fourthItem = [GMRowItem itemWithTitle:@"考试记录" image:[UIImage imageNamed:@"bbb"]];
    GMRowItem *fiveItem = [GMRowItem itemWithTitle:@"我的问题" image:[UIImage imageNamed:@"bbb"]];
    GMRowItem *sixItem = [GMRowItem itemWithTitle:@"我的笔记" image:[UIImage imageNamed:@"bbb"]];
    GMRowItem *sevenItem = [GMRowItem itemWithTitle:@"收藏资源" image:[UIImage imageNamed:@"bbb"]];
    GMRowItem *eightItem = [GMRowItem itemWithTitle:@"收藏题目" image:[UIImage imageNamed:@"bbb"]];
    GMRowItem *nineItem = [GMRowItem itemWithTitle:@"错题本" image:[UIImage imageNamed:@"bbb"]];
    GMGroupItem *group = [[GMGroupItem alloc]init];
    group.items = @[firstItem,secondItem,threeItem,fourthItem,fiveItem,sixItem,sevenItem,eightItem,nineItem];
    [self.dataSource addObject:group];
}
- (void) setGroupTwo{
    GMRowItem *firstItem = [GMRowItem itemWithTitle:@"今日任务"];
    firstItem.subTitle = @"五项未完成";
    GMRowItem *secondItem = [GMRowItem itemWithTitle:@"检查版本更新"];
    secondItem.subTitle = @"v1.0.6";
    GMRowItem *threeItem = [GMRowItem itemWithTitle:@"分享软件给好友"];
    GMRowItem *fourthItem = [GMRowItem itemWithTitle:@"问题建议反馈"];
    GMRowItem *fiveItem = [GMRowItem itemWithTitle:@"清除缓存"];
    fiveItem.subTitle = @"26MB";
    GMRowItem *sixItem = [GMRowItem itemWithTitle:@"关于我们"];
    GMGroupItem *group = [[GMGroupItem alloc]init];
    group.items = @[firstItem,secondItem,threeItem,fourthItem,fiveItem,sixItem];
    [self.dataSource addObject:group];
    [self.tabView reloadData];
}
- (UITableView *)tabView{
    if (!_tabView) {
        _tabView =[UITableView zj_tableViewWithSuperview:self.view delegate:self style:UITableViewStyleGrouped constraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view);
        }];
        [_tabView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        _tabView.showsVerticalScrollIndicator =NO;
    }
    return _tabView;
}
- (GMMyselfHeaderView *)headerView{
    if (!_headerView) {
        _headerView = [GMMyselfHeaderView viewFromXib];
        _headerView.frame = CGRectMake(0, 0, DEVICE_WIDTH, 150);
    }
    return _headerView;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        GMMyselfViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GMMyselfViewCell" forIndexPath:indexPath];
        GMGroupItem *group =self.dataSource[indexPath.section];
        GMRowItem *row = group.items[indexPath.row];
        cell.item = row;
        return cell;
    }else{
        GMMyselfSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GMMyselfSecondCell" forIndexPath:indexPath];
        GMGroupItem *group =self.dataSource[indexPath.section];
        GMRowItem *row = group.items[indexPath.row];
        cell.item = row;
        return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}
#pragma mark - TableView 的数据源方法

// 返回多少组(组)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSource.count;
}
// 返回每组有多少行(行)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    GMGroupItem *groupItem = self.dataSource[section];
    return groupItem.items.count;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH, 5)];
    view.backgroundColor = [UIColor colorRed:223 green:223 blue:223 alpha:1.0];
    return view;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH, 1)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 8;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.section) {
        case 0:{
            switch (indexPath.row) {
                case 0:{
                    //培训记录
                    GMTrainViewController *trainVC = [[GMTrainViewController alloc] init];
                    [self.navigationController pushViewController:trainVC animated:YES];
                }
                    break;
                case 1:{
                     //学习记录
                    GMStudyViewController *studyVC = [[GMStudyViewController alloc] init];
                    [self.navigationController pushViewController:studyVC animated:YES];
                }
                    break;
                case 2:{
                     //练习记录
                    GMPracticeViewController *practiveVC = [[GMPracticeViewController alloc] init];
                    [self.navigationController pushViewController:practiveVC animated:YES];
                }
                    break;
                case 3:{
                     //考试记录
                    GMExamViewController *exam = [[GMExamViewController alloc] init];
                    [self.navigationController pushViewController:exam animated:YES];
                }
                    break;
                case 4:{
                     //我的问题
                    GMQuestionViewController *qustion = [[GMQuestionViewController alloc] init];
                    [self.navigationController pushViewController:qustion animated:YES];
                }
                    break;
                case 5:{
                     //我的笔记
                    GMNotesViewController *notes = [[GMNotesViewController alloc] init];
                    [self.navigationController pushViewController:notes animated:YES];
                }
                    break;
                case 6:{
                     //收藏资源
                }
                    break;
                case 7:{
                     //收藏题目
                }
                    break;
                case 8:{
                     //错题本
                }
                    break;
                    
                default:
                    break;
            }
        }
            break;
        case 1:{
            switch (indexPath.row) {
                case 0:{
                     //今日任务
                    GMTodayTaskVC *today = [[GMTodayTaskVC alloc] init];
                    [self.navigationController pushViewController:today animated:YES];
                }
                    break;
                case 1:{
                     //检查版本更新
                }
                    break;
                case 2:{
                     //分享软件给好友
                }
                    break;
                case 3:{
                     //问题建议反馈
                }
                    break;
                case 4:{
                     //清除缓存
                }
                    break;
                case 5:{
                     //关于我们
                }
                    break;
                    
                default:
                    break;
            }
        }
            break;
            
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
